home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Freeware / Griffith 0.9.8 / griffith-0.9.8-win32.exe / {app} / lib / plugins / movie / PluginMovieKinoDe.py < prev    next >
Text File  |  2008-11-17  |  16KB  |  435 lines

  1. # -*- coding: UTF-8 -*-
  2.  
  3. __revision__ = '$Id: PluginMovieKinoDe.py 1042 2008-11-15 21:59:58Z mikej06 $'
  4.  
  5. # Copyright (c) 2006-2007
  6. #
  7. # This program is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 2 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. # GNU Library General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program; if not, write to the Free Software
  19. # 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
  20.  
  21. # You may use and distribute this software under the terms of the
  22. # GNU General Public License, version 2 or later
  23.  
  24. import gutils
  25. import movie
  26. import string
  27. import re
  28.  
  29. plugin_name = "Kino.de"
  30. plugin_description = "KINO.DE"
  31. plugin_url = "www.kino.de"
  32. plugin_language = _("German")
  33. plugin_author = "Michael Jahn"
  34. plugin_author_email = "<mikej06@hotmail.com>"
  35. plugin_version = "1.12"
  36.  
  37. class Plugin(movie.Movie):
  38.     url_to_use = "http://www.kino.de/kinofilm/"
  39.     url_type = "K"
  40.  
  41.     def __init__(self, id):
  42.         self.encode='iso-8859-1'
  43.         elements = string.split(id, "_")
  44.         self.movie_id = elements[1]
  45.         if (elements[0] == "V"):
  46.             self.url_to_use = "http://www.kino.de/videofilm/"
  47.             self.url_type = "V"
  48.         else:
  49.             self.url_to_use = "http://www.kino.de/kinofilm/"
  50.             self.url_type = "K"
  51.         self.url = self.url_to_use + str(self.movie_id)
  52.  
  53.     def initialize(self):
  54.         self.tmp_page = gutils.before(self.page, 'kinode_navi1')
  55.         self.url = self.url_to_use + string.replace(str(self.movie_id), '/', '/credits/')
  56.         self.open_page(self.parent_window)
  57.         self.tmp_creditspage = gutils.before(self.page, 'kinode_navi1')
  58.         self.url = self.url_to_use + string.replace(str(self.movie_id), "/", "/features/")
  59.         self.open_page(self.parent_window)
  60.         self.tmp_dvdfeaturespage = gutils.before(self.page, 'kinode_navi1')
  61.  
  62.     def get_image(self):
  63.         self.image_url = ''
  64.         tmpdata = self.regextrim(self.tmp_page, '(PRINT[-]CONTENT[-]START|<td class="content">)', '(Dieser Film wurde |>FOTOSHOW<|>KRITIK<)')
  65.         tmpdatasplit = re.split('src="http://.+/flbilder', tmpdata)
  66.         if len(tmpdatasplit) > 2:
  67.             tmpdata = gutils.before(tmpdatasplit[2], '.jpg')
  68.             if tmpdata <> '':
  69.                 self.image_url = 'http://images.kino.de/flbilder' + tmpdata + '.jpg'
  70.         elif len(tmpdatasplit) > 1:
  71.             tmpdata = gutils.before(tmpdatasplit[1], '.jpg')
  72.             if tmpdata <> '':
  73.                 self.image_url = 'http://images.kino.de/flbilder' + tmpdata + '.jpg'
  74.  
  75.     def get_o_title(self):
  76.         self.o_title = gutils.trim(self.tmp_page, 'span class="standardsmall">(', ')<')
  77.         if self.o_title == '':
  78.             if self.url_type == 'V':
  79.                 self.o_title = gutils.after(self.regextrim(self.tmp_page, 'headline2"[^>]*>[ \t\r\n]*<a href="/videofilm', '</a>'), '>')
  80.             else:
  81.                 self.o_title = gutils.after(self.regextrim(self.tmp_page, 'headline2"[^>]*>[ \t\r\n]*<a href="/kinofilm', '</a>'), '>')
  82.  
  83.     def get_title(self):
  84.         if self.url_type == "V":
  85.             self.title = gutils.after(self.regextrim(self.tmp_page, 'headline2"[^>]*>[ \t\r\n]*<a href="/videofilm', '</a>'), '>')
  86.         else:
  87.             self.title = gutils.after(self.regextrim(self.tmp_page, 'headline2"[^>]*>[ \t\r\n]*<a href="/kinofilm', '</a>'), '>')
  88.  
  89.     def get_director(self):
  90.         self.director = self.regextrim(self.tmp_creditspage, '>[ ]*Regie', '</a>')
  91.         self.director = gutils.after(self.director, '/star/')
  92.         self.director = gutils.after(self.director, '>')
  93.  
  94.     def get_plot(self):
  95.         # little steps to perfect plot (I hope ... it's a terrible structured content ... )
  96.         self.plot = gutils.before(self.tmp_page, '<!-- PRINT-CONTENT-ENDE-->')
  97.         self.plot = self.regextrim(self.plot, 'Kurzinfo', '</td></tr>[ \t\r\n]*<tr><td></td></tr>')
  98.         if self.plot != '':
  99.             lastpos = self.plot.rfind('</table>')
  100.             if lastpos == -1:
  101.                 self.plot = ''
  102.             else:
  103.                 self.plot = self.plot[lastpos:]
  104.         else:
  105.             self.plot = gutils.trim(self.tmp_page, '<span style="line-height:', '</spa')
  106.             if self.plot == '':
  107.                 self.plot = gutils.trim(self.tmp_page,"Kurzinfo", "</td></tr><tr><td></td>")
  108.                 if (self.plot == ''):
  109.                     self.plot = gutils.trim(self.tmp_page,"Kurzinfo", '<script ')
  110.                     self.plot = gutils.after(self.plot, '>')
  111.                 while len(self.plot) and string.find(self.plot, '</A>') > -1:
  112.                     self.plot = gutils.after(self.plot, '</A>');
  113.                 self.plot = gutils.after(gutils.after(self.plot, '</table>'), '>')
  114.             else:
  115.                 self.plot = gutils.after(self.plot, '>')
  116.  
  117.     def get_year(self):
  118.         self.year = ''
  119.         tmp = self.regextrim(self.tmp_page, 'span class="standardsmall"[^>]*><strong>', '</span>')
  120.         if tmp <> None:
  121.             srchresult = re.search('[0-9][0-9][0-9][0-9]</strong>', tmp)
  122.             if srchresult <> None:
  123.                 self.year = srchresult.string[srchresult.start():srchresult.end()]
  124.  
  125.     def get_runtime(self):
  126.         self.runtime = ''
  127.         srchresult = re.search('>[0-9]+[ \t]Min[.]<', self.tmp_page)
  128.         if srchresult <> None:
  129.             self.runtime = self.regextrim(srchresult.string[srchresult.start():srchresult.end()], '>', '[^0-9]')
  130.  
  131.     def get_genre(self):
  132.         self.genre = self.regextrim(self.tmp_page,'span class="standardsmall"[^>]*>[ \t\r\n]*<strong>((DVD|VHS|Laser Disc|Video CD|Blue-ray Disc)</strong>[ \t]-[ \t]<strong>)*', '</strong>[ \t]-[ \t]<strong>')
  133.  
  134.     def get_cast(self):
  135.         self.cast = gutils.trim(self.tmp_creditspage,'>Cast<', '</table><br')
  136.         if len(self.cast):
  137.             if self.cast.find('>mehr<') > 0:
  138.                 self.cast = gutils.after(self.cast, '>mehr<')
  139.             self.cast = gutils.after(self.cast, '>')
  140.             self.cast = re.sub('<tr[ ]+class="(dbtrefferlight|dbtrefferdark)">', "\n", self.cast)
  141.             self.cast = self.cast.replace(' ', '--flip--')
  142.             self.cast = gutils.clean(self.cast)
  143.             self.cast = re.sub("[\t]+", '', self.cast)
  144.             self.cast = re.sub("[\n]+", "\n", self.cast)
  145.             self.cast = re.sub("--flip--[\n]+", '--flip--', self.cast)
  146.             elements = self.cast.split("\n")
  147.             self.cast = ''
  148.             for element in elements:
  149.                 elements2 = element.split('--flip--')
  150.                 if len(elements2) > 1:
  151.                     if elements2[0] <> '':
  152.                         self.cast += elements2[1] + '--flip--' + elements2[0] + "\n"
  153.                     else:
  154.                         self.cast += elements2[1] + "\n"
  155.                 else:
  156.                     self.cast += element + "\n"
  157.             self.cast = string.replace(self.cast, '--flip--', _(' as ').encode('utf8'))
  158.  
  159.     def get_classification(self):
  160.         self.classification = self.regextrim(self.tmp_page,'FSK:( | )+', '</strong>')
  161.  
  162.     def get_studio(self):
  163.         self.studio = self.regextrim(self.tmp_page, '>[ ]*Verleih:( | )+', '( - | - )*</strong>')
  164.         if (self.studio == ""):
  165.             self.studio = self.regextrim(self.tmp_page, '>[ ]*Anbieter:( | )+', '( - | - )*</strong>')
  166.  
  167.     def get_o_site(self):
  168.         self.o_site = ""
  169.  
  170.     def get_site(self):
  171.         self.site = self.url_to_use + self.movie_id;
  172.  
  173.     def get_trailer(self):
  174.         self.trailer = ""
  175.  
  176.     def get_country(self):
  177.         self.country = self.regextrim(self.tmp_page, 'span class="standardsmall"[^>]*><strong>((DVD|VHS|Laser Disc|Video CD|Blue-ray Disc)</strong>[ \t]-[ \t]<strong>)*', '</span>')
  178.         if self.country <> None:
  179.             self.country = self.regextrim(self.country, '-[ \t]<strong>', '</strong>')
  180.             self.country = re.sub('[0-9]+$', '', self.country)
  181.         else:
  182.             self.country = ''
  183.  
  184.     def get_rating(self):
  185.         self.rating = "0"
  186.  
  187.     def get_notes(self):
  188.         self.notes = ""
  189.         tmp_notes = string.replace(gutils.strip_tags(gutils.trim(self.tmp_dvdfeaturespage, "<b>Sprache</b>", "</td></tr>")), " ", "")
  190.         if (tmp_notes != ""):
  191.             self.notes = self.notes + "Sprachen:\n" + tmp_notes + "\n\n"
  192.         tmp_notes = string.replace(gutils.strip_tags(gutils.trim(self.tmp_dvdfeaturespage, "<b>Untertitel</b>", "</td></tr>")), " ", "")
  193.         if (tmp_notes != ""):
  194.             self.notes = self.notes + "Untertitel:\n" + tmp_notes + "\n\n"
  195.         tmp_notes = string.replace(gutils.strip_tags(gutils.trim(self.tmp_dvdfeaturespage, "<b>Mehrkanalton</b>", "</td></tr>")), " ", "")
  196.         if (tmp_notes != ""):
  197.             self.notes = self.notes + "Mehrkanalton:\n" + tmp_notes + "\n\n"
  198.         tmp_notes = string.replace(gutils.strip_tags(gutils.trim(self.tmp_dvdfeaturespage, "<b>EAN</b>", "</td></tr>")), " ", "")
  199.         if (tmp_notes != ""):
  200.             self.notes = self.notes + "EAN:\n" + tmp_notes + "\n\n"
  201.             
  202.     def regextrim(self,text,key1,key2):
  203.         obj = re.search(key1, text)
  204.         if obj is None:
  205.             return ''
  206.         else:
  207.             p1 = obj.end()
  208.         obj = re.search(key2, text[p1:])
  209.         if obj is None:
  210.             return ''
  211.         else:
  212.             p2 = p1 + obj.start()
  213.         return text[p1:p2]
  214.  
  215. #
  216. # kino.de use iso-8859-1
  217. # it's not necessary to decode the page
  218. # in fact if utf-8 is used you can't search for movies with german umlaut
  219. # and if you use the decode call you get a terrible formatted result list
  220. #
  221.  
  222. class SearchPlugin(movie.SearchMovie):
  223.  
  224.     def __init__(self):
  225.         self.original_url_search   = 'http://www.kino.de/search.php?mode=megaSearch&searchCategory=film&inputSearch='
  226.         self.translated_url_search = 'http://www.kino.de/search.php?mode=megaSearch&searchCategory=film&inputSearch='
  227. #        self.encode='utf-8'
  228.         self.encode='iso-8859-1'
  229.  
  230.     def search(self,parent_window):
  231.         self.open_search(parent_window)
  232.         tmp_pagemovie = self.page
  233.         #
  234.         # try to get all result pages (not so nice, but it works)
  235.         #
  236.         tmp_pagecount = gutils.trim(tmp_pagemovie, '>von', '</a>')
  237.         try:
  238.             tmp_pagecountint = int(tmp_pagecount)
  239.         except:
  240.             tmp_pagecountint = 1
  241.         tmp_pagecountintcurrent = 1
  242.         while (tmp_pagecountint > tmp_pagecountintcurrent and tmp_pagecountintcurrent < 5):
  243.             tmp_pagecountintcurrent = tmp_pagecountintcurrent + 1
  244.             self.url = 'http://www.kino.de/search.php?mode=megaSearch&searchCategory=film&page=' + str(tmp_pagecountintcurrent) + "&inputSearch="
  245.             self.open_search(parent_window)
  246.             tmp_pagemovie = tmp_pagemovie + self.page
  247.         #
  248.         # Look for DVD and VHS
  249.         #
  250.         self.url = "http://www.kino.de/search.php?mode=megaSearch&searchCategory=video&inputSearch="
  251.         self.open_search(parent_window)
  252.         tmp_pagevideo = tmp_pagemovie + self.page
  253.         #
  254.         # try to get all result pages (not so nice, but it works)
  255.         #
  256.         tmp_pagecount = gutils.trim(self.page, '>von', '</a>')
  257.         try:
  258.             tmp_pagecountint = int(tmp_pagecount)
  259.         except:
  260.             tmp_pagecountint = 1
  261.         tmp_pagecountintcurrent = 1
  262.         while (tmp_pagecountint > tmp_pagecountintcurrent and tmp_pagecountintcurrent < 5):
  263.             tmp_pagecountintcurrent = tmp_pagecountintcurrent + 1
  264.             self.url = "http://www.kino.de/search.php?mode=megaSearch&searchCategory=video&page=" + str(tmp_pagecountintcurrent) + "&inputSearch="
  265.             self.open_search(parent_window)
  266.             tmp_pagevideo = tmp_pagevideo + self.page
  267.  
  268.         self.page = tmp_pagevideo
  269.         return self.page
  270.  
  271.     def get_searches(self):
  272.         elements1 = re.split('headline3"[^>]*>[ \t\r\n]*<a href="(http://www.kino.de)*/kinofilm/', self.page)
  273.         elements1[0] = None
  274.         for element in elements1:
  275.             if element <> None:
  276.                 self.ids.append("K_" + re.sub('[?].*', '', gutils.before(element,'"')))
  277.                 self.titles.append('Kino: ' + string.replace(string.replace(
  278.                     gutils.strip_tags(
  279.                         gutils.trim(element,'>','</a>') + ' (' +
  280.                         string.replace(
  281.                             gutils.trim(element, '<span class="standardsmall">', "</span>"),
  282.                             '<br />', ' - ')
  283.                         + ')'
  284.                     ),
  285.                     '( - (', '('), '))', ')')
  286.                 )
  287.  
  288.         elements2 = re.split('headline3"[^>]*>[ \t\r\n]*<a href="(http://www.kino.de)*/videofilm/', self.page)
  289.         elements2[0] = None
  290.         for element in elements2:
  291.             if element <> None:
  292.                 self.ids.append("V_" + re.sub('[?].*', '', gutils.before(element,'"')))
  293.                 self.titles.append('Video: ' + string.replace(string.replace(
  294.                     gutils.strip_tags(
  295.                         gutils.trim(element,'>','</a>') + ' (' +
  296.                         string.replace(
  297.                             gutils.trim(element, '<span class="standardsmall">', '</span>'),
  298.                             '<br />', ' - ')
  299.                         + ')'
  300.                     ),
  301.                     '( - (', '('), '))', ')')
  302.                 )
  303.  
  304. #
  305. # Plugin Test
  306. #
  307. class SearchPluginTest(SearchPlugin):
  308.     #
  309.     # Configuration for automated tests:
  310.     # dict { movie_id -> [ expected result count for original url, expected result count for translated url ] }
  311.     #
  312.     test_configuration = {
  313.         'Rocky Balboa'            : [ 6, 6 ],
  314.         'Arahan'                : [ 6, 6 ],
  315.         'Ein gl├╝ckliches Jahr'    : [ 3, 3 ]
  316.     }
  317.  
  318. class PluginTest:
  319.     #
  320.     # Configuration for automated tests:
  321.     # dict { movie_id -> dict { arribute -> value } }
  322.     #
  323.     # value: * True/False if attribute only should be tested for any value
  324.     #        * or the expected value
  325.     #
  326.     test_configuration = {
  327.         'K_rocky-balboa/96132.html' : { 
  328.             'title'             : 'Rocky Balboa',
  329.             'o_title'             : 'Rocky Balboa',
  330.             'director'            : 'Sylvester Stallone',
  331.             'plot'                 : True,
  332.             'cast'                : 'Sylvester Stallone' + _(' as ') + 'Rocky Balboa\n\
  333. Antonio Traver' + _(' as ') + 'Mason "The Line" Dixon\n\
  334. Burt Young' + _(' as ') + 'Paulie\n\
  335. Geraldine Hughes' + _(' as ') + 'Marie\n\
  336. Milo Ventimiglia' + _(' as ') + 'Rocky Jr.\n\
  337. James Francis Kelly III' + _(' as ') + 'Steps\n\
  338. Tony Burton' + _(' as ') + 'Duke\n\
  339. A.J. Benza' + _(' as ') + 'L.C.',
  340.             'country'            : 'USA',
  341.             'genre'                : 'Drama',
  342.             'classification'    : 'Freigegeben ab 12 Jahren',
  343.             'studio'            : 'Fox',
  344.             'o_site'            : False,
  345.             'site'                : 'http://www.kino.de/kinofilm/rocky-balboa/96132.html',
  346.             'trailer'            : False,
  347.             'year'                : 2006,
  348.             'notes'                : False,
  349.             'runtime'            : 102,
  350.             'image'                : True,
  351.             'rating'            : False
  352.         },
  353.         'K_ein-glueckliches-jahr/28675.html' : { 
  354.             'title'             : 'Ein gl├╝ckliches Jahr',
  355.             'o_title'             : 'La bonne ann├⌐e',
  356.             'director'            : 'Claude Lelouch',
  357.             'plot'                 : True,
  358.             'cast'                : 'Lino Ventura\n\
  359. Fran├ºoise Fabian\n\
  360. Charles G├⌐rard\n\
  361. Andr├⌐ Falcon',
  362.             'country'            : 'Frankreich/Italien',
  363.             'genre'                : 'Drama',
  364.             'classification'    : 'Freigegeben ab 12 Jahren',
  365.             'studio'            : 'Columbia TriStar',
  366.             'o_site'            : False,
  367.             'site'                : 'http://www.kino.de/kinofilm/ein-glueckliches-jahr/28675.html',
  368.             'trailer'            : False,
  369.             'year'                : 1973,
  370.             'notes'                : False,
  371.             'runtime'            : 115,
  372.             'image'                : False,
  373.             'rating'            : False
  374.         },
  375.         'V_ein-glueckliches-jahr-dvd/85546.html' : { 
  376.             'title'             : 'Ein gl├╝ckliches Jahr',
  377.             'o_title'             : 'La bonne ann├⌐e',
  378.             'director'            : 'Claude Lelouch',
  379.             'plot'                 : True,
  380.             'cast'                : 'Lino Ventura\n\
  381. Fran├ºoise Fabian\n\
  382. Charles G├⌐rard\n\
  383. Andr├⌐ Falcon',
  384.             'country'            : 'Frankreich/Italien',
  385.             'genre'                : 'Drama',
  386.             'classification'    : 'Freigegeben ab 12 Jahren',
  387.             'studio'            : 'Black Hill Pictures',
  388.             'o_site'            : False,
  389.             'site'                : 'http://www.kino.de/videofilm/ein-glueckliches-jahr-dvd/85546.html',
  390.             'trailer'            : False,
  391.             'year'                : 1973,
  392.             'notes'                : 'Sprachen:\n\
  393. Deutsch DD 2.0, Franz├╢sisch DD 2.0\n\
  394. \n\
  395. Mehrkanalton:\n\
  396. Dolby Digital 2.0\n\
  397. \n\
  398. EAN:\n\
  399. 7321921998843',
  400.             'runtime'            : 110,
  401.             'image'                : True,
  402.             'rating'            : False
  403.         },
  404.         'V_arahan-vanilla-dvd/90405.html' : { 
  405.             'title'             : 'Arahan (Vanilla-DVD)',
  406.             'o_title'             : 'Arahan jangpung dae jakjeon',
  407.             'director'            : 'Ryoo Seung-wan',
  408.             'plot'                 : True,
  409.             'cast'                : 'Ryu Seung-beom' + _(' as ') + 'Sang-hwan\n\
  410. Yoon So-yi' + _(' as ') + 'Wi-jin\n\
  411. Ahn Sung-kee' + _(' as ') + 'Ja-woon\n\
  412. Jung Doo-hong' + _(' as ') + 'Heuk-woon\n\
  413. Yun Ju-sang' + _(' as ') + 'Mu-woon',
  414.             'country'            : 'S├╝dkorea',
  415.             'genre'                : 'Action/Kom├╢die',
  416.             'classification'    : 'Freigegeben ab 16 Jahren',
  417.             'studio'            : 'Splendid',
  418.             'o_site'            : False,
  419.             'site'                : 'http://www.kino.de/videofilm/arahan-vanilla-dvd/90405.html',
  420.             'trailer'            : False,
  421.             'year'                : 2004,
  422.             'notes'                : 'Sprachen:\n\
  423. Deutsch DD 5.1\n\
  424. \n\
  425. Mehrkanalton:\n\
  426. Dolby Digital 5.1\n\
  427. \n\
  428. EAN:\n\
  429. 4013549871105',
  430.             'runtime'            : 108,
  431.             'image'                : True,
  432.             'rating'            : False
  433.         }
  434.     }
  435.